package com.hudson.core.json;

import com.google.gson.*;

import java.lang.reflect.Type;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author: 渔小鲤
 * @DateTime: 2025/7/13 2:10
 **/
public class AtomicIntegerTypeAdapter  implements JsonSerializer<AtomicInteger>, JsonDeserializer<AtomicInteger> {
    @Override
    public AtomicInteger deserialize(JsonElement json, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
        return new AtomicInteger(json.getAsInt());
    }

    @Override
    public JsonElement serialize(AtomicInteger src, Type type, JsonSerializationContext jsonSerializationContext) {
        return new JsonPrimitive(src.get());
    }
}
